#ifndef _RTP_H_
#define _RTP_H_

#include <stdint.h>

#define RTP_VESION 2
#define RTP_PAYLOAD_TYPE_H26X 96
#define RTP_PAYLOAD_TYPE_AAC 97
#define RTP_PAYLOAD_TYPE_PCMA 8
#define MAX_RTP_PAYLOAD_SIZE 1400

enum RTP_PAYLOAD_TYPE {
	RTP_H264 = 0,
	RTP_H265,
	RTP_AAC,
	RTP_PCMA
};

struct rtp_packetizer;
typedef void (*rtp_data_callback)(void*, int, void*);
typedef int (*rtp_pack_function)(struct rtp_packetizer*, char*, int, uint32_t);

struct rtp_header
{
	/* byte 0 */
	uint8_t csrcLen : 4;
	uint8_t extension : 1;
	uint8_t padding : 1;
	uint8_t version : 2;

	/* byte 1 */
	uint8_t payloadType : 7;
	uint8_t marker : 1;

	/* bytes 2,3 */
	uint16_t seq;

	/* bytes 4-7 */
	uint32_t timestamp;

	/* bytes 8-11 */
	uint32_t ssrc;
};

struct rtp_packet
{
	struct rtp_header header;
	uint8_t payload[0];
};

struct rtp_packetizer {
    struct rtp_packet* packet;
    enum RTP_PAYLOAD_TYPE payloadType;
    rtp_data_callback callback;
    rtp_pack_function input;
    uint16_t seq;
    void* usr_data;
};

struct rtp_packetizer* create_rtp_packetizer(int payloadType, uint32_t ssrc, rtp_data_callback callback, void* usr_data);
int rtp_payload_encode_input(struct rtp_packetizer *packetizer, void *data, int len, uint32_t timestamp);
void rtp_packetizer_destroy(struct rtp_packetizer *packetizer);

#endif